import { Column, Entity, PrimaryColumn } from 'typeorm';
import { address } from './address.entity';
import { ApiProperty } from '@midwayjs/swagger';
import { Rule, RuleType, getSchema } from '@midwayjs/validate';
@Entity({
  name: 'area',
  synchronize: false,
})
export class Area {
  @ApiProperty({ example: 'Ar' })
  @Rule(RuleType.string().min(0).required())
  @PrimaryColumn({ type: 'varchar', length: 32 })
  areaCode: string;
  @ApiProperty({ example: '华南区域' })
  @Rule(RuleType.string().allow(null).min(0).required())
  @Column({ type: 'varchar', length: 32 })
  areaName: string;
  @ApiProperty({ example: new Date() })
  @Rule(RuleType.date().allow(null).min(0).required())
  @Column()
  createTime: Date;
  @Rule(RuleType.array().items(getSchema(address)).required())
  address: Array<address> = [];
}
export class AreaQC {
  @ApiProperty({ example: '华南区域' })
  @Rule(RuleType.string().allow(null).min(0).required())
  areaNameLike: string;
  @ApiProperty({ example: '潍坊' })
  @Rule(RuleType.string().allow(null).min(0).required())
  cityNameLike: string;
  @ApiProperty({ example: '潍坊-寿光市稻田镇阁后张村' })
  @Rule(RuleType.string().allow(null).min(0).required())
  addressNameLike: string;
  @ApiProperty({ example: new Date() })
  @Rule(RuleType.date().allow(null).min(0).required())
  minTime: Date;
  @ApiProperty({ example: new Date() })
  @Rule(RuleType.date().allow(null).min(0).required())
  maxTime: Date;
  @ApiProperty({ example: 1 })
  @Rule(RuleType.number().allow(null).min(0).required())
  pageNum: number;
  @ApiProperty({ example: 5 })
  @Rule(RuleType.number().allow(null).min(0).required())
  pageSize: number;
}
export class AreaInsertDto {
  @ApiProperty({ example: 'Ar' })
  @Rule(RuleType.string().min(0).required())
  areaCode: string;
  @ApiProperty({ example: '华南区域' })
  @Rule(RuleType.string().allow(null).min(0).required())
  areaName: string;
  @ApiProperty({
    example: [
      {
        addressCode: '3',
        addressName: '淄博-张店',
        cityName: '淄博',
        addressFk: '1',
      },
      {
        addressCode: '3',
        addressName: '淄博-博山',
        cityName: '淄博',
        addressFk: '1',
      },
    ],
  })
  @Rule(RuleType.array().items(getSchema(address)).required())
  address: Array<address> = [];
}
